//
//  pointerConst.cpp
//  learnC++
//
//  Created by apple on 2018/5/30.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "pointerConst.hpp"


void test_pointer_const(){
    
    int res = 5; // value is not constant
    const int *resPtr = &res; // this is still okay
    
    
    const int value = 5; // value is const
    const int *ptr = &value;

    
    //声明*ptr2为const类型
    int value2 = 4;
    const int *ptr2 = &value2;//表示*ptr2为常量不能修改（它定义*ptr2为const int类型，所以可以改ptr2的指向），但可以直接修改value。

    ptr2 = &value;
    
    value2 = 7;
    
    
//    int value1 = 5;
//    const int *ptr = &value1; // ptr points to a const int
//
//    int value2 = 6;
//    ptr = &value2;
    
    //声明const指针
    int value3 = 6;
    int * const ptr3 = &value3;//此时指针不能修改指向
    
    
    int value4 = 5;
    int *const ptr4 = &value4; // ptr will always point to value
    *ptr4 = 6;
    
    //const指针 const值
    int value5 = 5;
    const int *const ptr5 = &value5;
    
    
    
}

